package com.tuju.jetpackfirstdemo.ui.k;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import com.google.gson.Gson;
import com.tuju.jetpackfirstdemo.R;
import com.tuju.jetpackfirstdemo.utils.TextResourceReader;
import com.tuju.jetpackfirstdemo.widget.KLineView;

import java.util.List;

public class KLineActivity extends AppCompatActivity {

    private KLineView k_view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kline);
        k_view = findViewById(R.id.k_view);
        initData();
    }

    private void initData() {
        String result = TextResourceReader.readTextFileFromAssets(this, "kline.json");
        KBeanResult beanResult = new Gson().fromJson(result, KBeanResult.class);
        if (beanResult != null && beanResult.getMessage() != null) {
            List<Float> yDatas = beanResult.getMessage().getY();
            List<String> xTime = beanResult.getMessage().getX();
            List<KBean.DataBean> dataValue = beanResult.getMessage().getData();
            k_view.setCoordinate(yDatas,xTime,dataValue);
        }
    }

    //旋转90度
    public void rotate(View view) {
        k_view.setPivotX(k_view.getWidth()/2);
        k_view.setPivotY(k_view.getHeight()/2);//支点在图片中心
        k_view.setRotation(90);
    }

}
